﻿using System;
using System.ServiceModel;

namespace Arete
{
    internal class FormsEventServiceClient : DuplexClientBase<IMyContract>, IMyContract
    {
        public FormsEventServiceClient(InstanceContext eventCntx)
            : base(eventCntx)  { }

        public void DoSomethingAndFireEvent()
        {
            Channel.DoSomethingAndFireEvent();
        }

        public void SendMessageAndFireEvent(string message)
        {
            Channel.SendMessageAndFireEvent(message);
        }

        public void SubscribeEvent() { Channel.SubscribeEvent(); }

    }

    class MyFormsSubscriber : IMyEvents
    {
        public void Event1()
        {
            AppMain.ClientForm.ShowMessage(string.Format(
                "Event is subscribed from the service at {0}",
                DateTime.Now));
        }

        public void MessageEvent(object obj, MessageEventArgs e)
        {
            AppMain.ClientForm.ShowMessage(string.Format(
                "Event {0} is subscribed from the service at {1}",
                e.MessageText, DateTime.Now));
        }
    }
}
